<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{number}}.{{title}}</title>
    <!-- 引入Google字体 -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&family=Poppins:wght@400;600&display=swap">
    <!-- 引入CDN -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript"
        charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ext-language_tools.js" type="text/javascript"
        charset="utf-8"></script>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            font-family: 'Poppins', sans-serif;
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }

        .container {
            width: 100%;
            height: 100%;
        }


        /* 导航栏样式 */
        .navbar {
            width: 100%;
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            padding: 10px 20px;
            position: fixed;
            top: 0;
            z-index: 1000;
            display: flex;
            align-items: center;
            justify-content: flex-start;
        }

        .navbar a {
            color: #333;
            text-decoration: none;
            font-size: 16px;
            margin-left: 30px;
            /* 调整间距 */
            position: relative;
            font-weight: 500;
        }

        .navbar a:first-child {
            margin-left: 0;
            /* 确保第一个链接没有左间距 */
        }

        .navbar a::after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 0;
            width: 0;
            height: 2px;
            background-color: #4CAF50;
            transition: width 0.3s;
        }

        .navbar a:hover::after {
            width: 100%;
        }

        .navbar .logo {
            font-size: 24px;
            font-weight: 600;
            color: #4CAF50;
            letter-spacing: 2px;
            text-transform: uppercase;
            margin-right: 30px;
            /* 调整logo与第一个链接之间的间距 */
        }

        /* Part 1 样式 */
        .part1 {
            display: flex;
            width: 100%;
            height: 600px;
            padding-top: 70px;
        }

        .left_desc {
            width: 50%;
            padding: 20px;
            overflow-y: auto;
            box-sizing: border-box;
        }

        .left_desc h3 {
            margin-bottom: 15px;
            font-size: 24px;
            font-weight: 600;
        }

        .left_desc pre {
            font-size: medium;
            font-family: 'Roboto', sans-serif;
        }

        .right_code {
            width: 50%;
            box-sizing: border-box;
        }

        .ace_editor {
            height: 100%;
            font-family: 'Roboto', sans-serif;
        }

        /* Part 2 样式 */
        .part2 {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px;
            box-sizing: border-box;
        }

        .result {
            width: calc(100% - 150px);
        }

        .btn-submit {
            width: 120px;
            height: 50px;
            font-size: large;
            background: #26bb9c;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s, color 0.3s;
        }

        .btn-submit:hover {
            background-color: #219b84;
            color: #fff;
        }

        .result pre {
            font-size: large;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .navbar a {
                display: block;
                margin: 10px 0;
            }

            .navbar {
                flex-direction: column;
            }

            .part1 {
                flex-direction: column;
            }

            .left_desc,
            .right_code {
                width: 100%;
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="navbar">
            <div class="logo">OJ Platform☰</div>
            <a href="/bch">首页</a>
            <a href="/all_questions">题库</a>
            <a href="/answer/{{number}}">题解</a>
        </div>
        <div class="part1">
            <div class="left_desc">
                <h3><span id="number">{{number}}</span>.{{title}}.{{star}}</h3>
                <pre>{{desc}}</pre>
            </div>
            <div class="right_code">
                <pre id="code" class="ace_editor"><textarea class="ace_text-input">{{pre_code}}</textarea></pre>
            </div>
        </div>
        <div class="part2">
            <div class="result">
                <p>运行结果</p>
            </div>
            <button class="btn-submit" onclick="submit()">提交代码</button>
        </div>
    </div>
    <script>
        // 初始化编辑器
        var editor = ace.edit("code");

        // 设置编辑器风格和语言
        editor.setTheme("ace/theme/chrome");
        editor.session.setMode("ace/mode/c_cpp");

        // 编辑器配置
        editor.setFontSize(16);
        editor.getSession().setTabSize(2);
        editor.setReadOnly(false);

        // 启用自动完成
        ace.require("ace/ext/language_tools");
        editor.setOptions({
            enableBasicAutocompletion: true,
            enableSnippets: true,
            enableLiveAutocompletion: true
        });

        // 提交代码
        function submit() {
            var code = editor.getSession().getValue();
            var number = $("#number").text();
            var judge_url = "/judge/" + number;

            $.ajax({
                method: "POST",
                url: judge_url,
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({
                    "code": code,
                    "input": ""
                }),
                success: function (data) {
                    show_result(data);
                }
            });
        }

        // 显示结果
        function show_result(data) {
            var result_div = $(".result");
            result_div.empty();

            var reason_label = $("<p>").text(data.reason);
            result_div.append(reason_label);

            if (data.status == 0) {
                var stdout_label = $("<pre>").text(data.stdout);
                var stderr_label = $("<pre>").text(data.stderr);
                result_div.append(stdout_label).append(stderr_label);
            }
        }
    </script>
</body>

</html>